<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
class Custom_View_Helper_Pagination extends Zend_View_Helper_Abstract
{
	public function pagination($paginator = null, $scrollingStyle = null, $isAjax = false)
	{
		if($paginator == null) $paginator = $this->view->paginator;
		if($scrollingStyle == null) $scrollingStyle = 'Sliding';

		$pagination = '';

		if($paginator)
		{
			$pages = $paginator->getPages($scrollingStyle);
            
			if ($pages->pageCount > 1)
			{
				$pagination .= '<div class="paginator">';

				//Previous page link
				if (isset($pages->previous))
					$pagination .= $this->getLink($pages->previous, '&laquo;', $isAjax);
				

				foreach($pages->pagesInRange as $page)
				{
					if($page == $pages->current)
						$pagination .= '<a class="active">'.$page.'</a>';
					else
						$pagination .= $this->getLink($page, $page, $isAjax);
				}

				//Next page link
				if (isset($pages->next))
					$pagination .= $this->getLink($pages->next, '&raquo;', $isAjax);
				
				$pagination .= '</div>';
			}
		}
		return $pagination;
	}

	private function getLink($page, $label, $isAjax = false)
	{
		$urlParams = array('page' => $page);
		$request = Zend_Controller_Front::getInstance()->getRequest();
		//echo $this->view->url();
        if($isAjax)
            $link = '<a href="javascript:void(0)" class="plink" p:url= "'.$this->view->url($urlParams).'" >'.$label.'</a>';
        else
            $link = '<a href="'. $this->view->url($urlParams).'">'.$label.'</a>';

		return $link;
	}
}

?>
